<!---{
"title": "Building quick-lint-js from source using Nix",
"navTitle": "Nix build"
}--->

<!DOCTYPE html>
<!-- Copyright (C) 2020  Matthew "strager" Glazar -->
<!-- See end of file for extended copyright information. -->
<html>
  <head>
    <%- await include("../../../common-head.ejs.html") %>
    <link href="../../../main.css" rel="stylesheet" />
  </head>
  <body class="side-bar-nav">
    <header><%- await include("../../../common-nav.ejs.html") %></header>

    <main>
      <h1><qljs-icon name="nix" size="29" /> <%= meta.title %></h1>

      <p>
        Building quick-lint-js from source using Nix is for advanced users only.
        You need to
        <a href="https://nixos.org/download.html"
          >install the Nix package manager</a
        >
        if you have not already done so.
      </p>

      <p>
        <a href="https://nixos.org/manual/nix/stable/">Nix</a> uses derivation
        files that contain instructions for automation on how to build and
        package software. The <code>dist/</code> folder contains such
        derivations for quick-lint-js and can be used to download dependencies
        and build it.
      </p>

      <h3>0. Prepare environment</h3>

      <p>
        The derivations in <code>dist/</code> contain the necessary dependencies
        to build quick-lint-js using cmake and ninja. We can use
        <code>nix-shell</code> to download those dependencies and make them
        available for development.
      </p>
      <blockquote>
        <pre><code class="shell-session"><kbd>nix-shell dist/nix/shell.nix</kbd></code></pre>
      </blockquote>

      <p>
        While it seems this does not do anything, you will be dropped in a shell
        that has the build tools available necessary to build quick-lint-js.
        Once you exit this shell, the downloaded dependencies will not be
        available anymore. You can use the above command again to re-create a
        shell with the build tools available at any time.
      </p>

      <h3>1. Configure</h3>

      <p>After running above command, we configure the build environment:</p>
      <blockquote>
        <pre><code class="shell-session"><kbd>cmakeConfigurePhase</kbd></code></pre>
      </blockquote>

      <p>
        This will create a <code>build/</code> folder in the project folder and
        changes the current directory to it.
      </p>

      <h3>2. Build</h3>

      <p>
        To build quick-lint-js, make sure you are in the
        <code>build/</code> folder; the previous command should have already put
        you there. To start the build using ninja, you use:
      </p>
      <blockquote>
        <pre><code class="shell-session"><kbd>ninjaBuildPhase</kbd></code></pre>
      </blockquote>

      <h3>3. Run</h3>

      <p>
        After building, the binary is available as <code>quick-lint-js</code> in
        the build folder:
      </p>
      <blockquote>
        <pre><code class="shell-session"><kbd>./quick-lint-js --help</kbd></code></pre>
      </blockquote>

      <p>To run the tests, execute the test binary in the build directory:</p>
      <blockquote>
        <pre><code class="shell-session"><kbd>./test/quick-lint-js-test</kbd></code></pre>
      </blockquote>
    </main>

    <footer><%- await include("../../../common-footer-nav.ejs.html") %></footer>
  </body>
</html>

<!--
quick-lint-js finds bugs in JavaScript programs.
Copyright (C) 2020  Matthew "strager" Glazar

This file is part of quick-lint-js.

quick-lint-js is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

quick-lint-js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with quick-lint-js.  If not, see <https://www.gnu.org/licenses/>.
-->
